package org.dlx.drpc.core.common;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;

import java.util.List;

public class RPCEncoder extends MessageToMessageEncoder<Object>
{
    private IRPCEncoder encoder;

    public RPCEncoder(IRPCEncoder e){
        this.encoder = e;
    }
    @Override
    protected void encode(ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception
    {
        if(this.encoder == null)
            return;
        Message message = new Message(this.encoder.encode(msg));
        out.add(message);
    }
}
